package com.lyj.system.service.user.impl;

import com.lyj.common.core.enums.ResultCode;
import com.github.pagehelper.PageHelper;
import com.lyj.security.exception.ServiceException;
import com.lyj.system.domain.user.User;
import com.lyj.system.domain.user.dto.UserDTO;
import com.lyj.system.domain.user.dto.UserQueryDTO;
import com.lyj.system.domain.user.vo.UserVO;
import com.lyj.system.mapper.user.UserMapper;
import com.lyj.system.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2025-08-23
 * Time: 11:24
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public List<?> list(UserQueryDTO userQueryDTO) {
        PageHelper.startPage(userQueryDTO.getPageNum(),userQueryDTO.getPageSize());
        List<UserVO> userVOS = userMapper.selectUserList(userQueryDTO);
        return userVOS;
    }

    @Override
    public int updateStatus(UserDTO userDTO) {
        //判断用户是否存在
        User user = userMapper.selectById(userDTO.getUserId());
        if(user == null){
            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);
        }
        user.setStatus(userDTO.getStatus());
        //TODO
        return userMapper.updateById(user);
    }
}
